package com.library.dao.impl;

import com.library.bean.Book;
import com.library.bean.User;
import com.library.dao.BaseDao;
import com.library.dao.BookDao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 * @Author:qjc
 * @Date: 2024/9/14 20:20
 * @Description:
 */
public class BookDaoImpl implements BookDao {

    @Override
    public List<Book> bookSelect() {
        Connection conn= BaseDao.getConn();//打开连接
        String sql = "SELECT * FROM book";
        List<Book> list = new ArrayList<Book>();
        PreparedStatement ps= null;
        ResultSet rs=null;
        try {
            ps= conn.prepareStatement(sql);
            rs = ps.executeQuery();
            while(rs.next()) {
               Book book=new Book();
                book.setBookId(rs.getInt("bookId"));
                book.setBookName(rs.getString("bookName"));
                book.setBookType(rs.getString("bookType"));
                book.setBookWriter(rs.getString("bookWriter"));
                list.add(book);
            }
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }finally {
            BaseDao.closeAll(conn, ps,rs);
        }
        return list;
    }
}
